//
//  CGQduankouClassViewController.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/4/21.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit

import PagingViewKit
class CGQduankouClassViewController:SYBaseViewController,PagingTitleViewDelegate, PagingContentCollectionViewDelegate {
    
    var id: String!
    var model: NSPortguanliRecordsModel!
    
    init(id: String,model:NSPortguanliRecordsModel) {
        
        super.init(nibName: nil, bundle: nil)
        self.id = id
        self.model = model
        
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    deinit {
        print("ScrollVC - deinit")
    }
    
    override func viewWillAppear(_ animated: Bool) {
        self.navigationController?.navigationBar.isHidden = true
        self.tabBarController?.tabBar.isHidden = true
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        view.addSubview(pagingTitleView)
        view.addSubview(pagingContentView)
        view.addSubview(imgView)
        imgView.snp.makeConstraints { (make) in
                    make.left.equalToSuperview()
                    make.top.equalToSuperview().offset(STATUSBAR_HEIGHT)
                    make.height.equalTo(48.autoWidth())
                    make.width.equalTo(30.autoWidth())
                }
    }
    
    var imgView: VGImageButton = {
        
        let v: VGImageButton = VGImageButton()
        v.imageView.image = UIImage(named: "back_black")
        v.btn.addTarget(self, action: #selector(closeBtAction), for: .touchUpInside)
        return v
    }()
    
    lazy var pagingTitleView: PagingTitleView = {
        let configure: PagingTitleViewConfigure = PagingTitleViewConfigure()
        configure.indicatorScrollStyle = .Half
        configure.indicatorType = .Dynamic
        configure.showBottomSeparator = false
        configure.showIndicator = false
        configure.color = UIColor(hex: 0x999999)
        configure.selectedColor = UIColor(hex: 0x333333)
        
        let frame = CGRect.init(x: 30, y:STATUSBAR_HEIGHT, width: view.frame.size.width-60, height: 44)
        let titles = ["端口详情", "历史数据"]
        let pagingTitle = PagingTitleView(frame: frame, titles: titles, delegate: self, configure: configure)
        return pagingTitle
    }()
    
    lazy var pagingContentView: PagingContentCollectionView = {
       let firvc = CGQduankouDetailVC(model: self.model)

        let secvc = CGQLishiListViewController(portNumber:self.id)

        let vcs = [firvc, secvc]
        
        let y: CGFloat = pagingTitleView.frame.maxY
        let tempRect: CGRect = CGRect.init(x: 0, y: y, width: view.frame.size.width, height: view.frame.size.height - y)
        let pagingContent: PagingContentCollectionView = PagingContentCollectionView(frame: tempRect, parentVC: self, childVCs: vcs)
        pagingContent.delegate = self
        return pagingContent
    }()
    
    @objc func closeBtAction() {
        
        self.sy_popVC()
    }

    func pagingContentCollectionView(pagingContentCollectionView: PagingContentCollectionView, progress: CGFloat, currentIndex: Int, targetIndex: Int) {
        pagingTitleView.setPagingTitleView(progress: progress, currentIndex: currentIndex, targetIndex: targetIndex)
    }
    
    func pagingTitleView(pagingTitleView: PagingTitleView, index: Int) {
        pagingContentView.setPagingContentCollectionView(index: index)
    }
}
